package com.wg.controller;

import com.wg.entity.WGInfo;
import com.wg.service.WGInfoService;
import com.wg.utils.JsonObject;
import com.wg.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/wginfo")
public class WGInfoController {
    @Resource
    private WGInfoService wgInfoService;
    @RequestMapping("/findAll")
    public JsonObject findAll() {
        List<WGInfo> wgInfos = wgInfoService.findAll();
        JsonObject object = new JsonObject(200, "查询成功", (long) wgInfos.size(), wgInfos);
        return object;
    }
    @ApiOperation(value = "删除")
    @RequestMapping("/deleteByIds")
    public R delete(String  ids){
        List<String> list= Arrays.asList(ids.split(","));
        //遍历遍历进行删除
        for(String id:list){
            wgInfoService.deleteById(Integer.parseInt(id));
        }
        return R.ok();
    }


    @ApiOperation(value = "新增")
    @RequestMapping("/add")
    public R add(@RequestBody WGInfo wgInfo){
        wgInfo.creator="aaa";
        wgInfoService.addUser(wgInfo);
        return R.ok();
    }


    @ApiOperation(value = "更新")
    @RequestMapping("/update")
    public R update(@RequestBody WGInfo wgInfo){
        boolean num= wgInfoService.updateById(wgInfo);
        if(num){
            return R.ok();
        }else{
            return R.fail("修改失败");
        }
    }
    @RequestMapping("/findById")
    public WGInfo findById(@RequestBody Integer wgId) {
        return wgInfoService.findById(wgId);
    }
    @RequestMapping("/findmemberById")
    public ArrayList findmemberById(@RequestBody Integer wgId) {
        return wgInfoService.findById(wgId).member;
    }


}